package com.shop.shoppingmall.controller;

import com.shop.shoppingmall.dao.ShUserDao;
import com.shop.shoppingmall.entity.ShDayCoin;
import com.shop.shoppingmall.entity.ShUser;
import com.shop.shoppingmall.service.ShDayCoinService;
import com.shop.shoppingmall.util.CommonConstant;
import com.shop.shoppingmall.util.JwtUtil;
import com.shop.shoppingmall.util.api.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 馨天币明细(ShDayCoin)表控制层
 *
 * @author makejava
 * @since 2020-09-11 10:59:03
 */
@RestController
@RequestMapping("shDayCoin")
@CrossOrigin
public class ShDayCoinController {
    /**
     * 服务对象
     */
    @Resource
    private ShDayCoinService shDayCoinService;
    @Resource
    private ShUserDao shUserDao;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ShDayCoin selectOne(String id) {
        return this.shDayCoinService.queryById(id);
    }


    /**
     * 查询馨天币明细
     * @param map
     * @param request
     * @return
     */
    @PostMapping("queryAll")
    public Result queryAll(@RequestBody Map map, HttpServletRequest request){
        String name = JwtUtil.getUserNameByToken(request);
        ShUser shUser = shUserDao.selectLoginName(name);
        if(shUser == null || name == null){
            return Result.error(CommonConstant.SC_OK_201,"您还未注册或者登录，请先注册或登录");
        }
        map.put("userId",shUser.getId());
        return shDayCoinService.queryAll(map);
    }

    @PostMapping("/queryDayCoinAll")
    public Result queryDayCoinAll(@RequestBody Map map){
        return shDayCoinService.queryDayCoinAll(map);
    }

}
